package com.lmbx.shzh.controller;

import com.lmbx.shzh.domain.common.ResponseResult;
import com.lmbx.shzh.service.WeatherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;


/**
 * @Auther: wyl
 * @Date: 2021/5/12
 * @Description: 雷达图服务
 */
@Slf4j
@Api(tags = "雷达图模块", value = "雷达图模块相关接口")
@RestController
@Validated
@RequestMapping("api/v1/weather")
public class WeatherController {

    @Autowired
    private WeatherService weatherService;

    @ApiOperation("获得华北地区最新雷达图信息")
    @GetMapping("getWeather")
    public ResponseResult getWeather(@RequestParam(value = "num", required = true) @NotNull(message = "雷达图获得个数不能为空") @Min(value = 1, message = "雷达图最小获得1张") @Max(value = 24, message = "雷达图最大获得24张") int num) {

        return weatherService.getWeather(num);
    }

    @ApiOperation("获得时间段内华北地区雷达图信息")
    @GetMapping("getWeatherList")
    public ResponseResult getWeatherList(@RequestParam(value = "startTime", required = true) @NotNull(message = "开始时间不能为空") @Min(value = 1000000000000L, message = "开始时间不合法，必须为毫秒值") @Max(value = 9999999999999L, message = "开始时间不合法，必须为毫秒值") long startTime,
                                         @RequestParam(value = "endTime",required = true) @NotNull(message = "结束时间不能为空") @Min(value = 1000000000000L, message = "结束时间不合法，必须为毫秒值") @Max(value = 9999999999999L, message = "结束时间不合法，必须为毫秒值") long endTime) {

        return weatherService.getWeatherList(startTime, endTime);
    }
    @ApiOperation("获取气象云图信息")
    @PostMapping("getWthCloud")
    public ResponseResult getWthCloud(@RequestParam(value = "num", required = true) @NotNull(message = "雷达图获得个数不能为空") @Min(value = 1, message = "雷达图最小获得1张") @Max(value = 24, message = "雷达图最大获得24张") int num){
        return weatherService.getWthCloud(num);
    }
    @ApiOperation("获得时间段云图信息")
    @PostMapping("getWthCloudList")
    public ResponseResult getWthCloudList(@RequestParam(value = "startTime", required = true) @NotNull(message = "开始时间不能为空") @Min(value = 1000000000000L, message = "开始时间不合法，必须为毫秒值") @Max(value = 9999999999999L, message = "开始时间不合法，必须为毫秒值") long startTime,
                                         @RequestParam(value = "endTime",required = true) @NotNull(message = "结束时间不能为空") @Min(value = 1000000000000L, message = "结束时间不合法，必须为毫秒值") @Max(value = 9999999999999L, message = "结束时间不合法，必须为毫秒值") long endTime) {

        return weatherService.getWthCloudList(startTime, endTime);
    }
}
